var url = {
	common: 'https://www.simonwei.club',
	// common: 'http://192.168.0.119:9001/word',
	basic: 'https://www.simonwei.club/word/extra/'
	// basic: 'http://192.168.0.119:9001/word/extra/'
}
var token = {
	local: window.localStorage.token,
	getUser: function(token) {
		if (token) {
			$.ajax({
				type: "POST",
				dataType: "json",
				beforeSend: function(XMLHttpRequest) {
					XMLHttpRequest.setRequestHeader("token", token);
				},
				url: url.basic + 'info',
				data: '',
				success: function(res) {
					console.log("获取用户信息", res)
					if (res.success) {
						$("#userName").text(res.data.realName);
						$("#userId").text(res.data.id);
					} else {
						tool.tips(res.message)
						window.location.href = "login.html"
					}
				},
				error: function(err) {
					console.log(err)
				}
			})
		} else {
			window.location.href = "login.html"
		}
	}
}
var tool = {
	// 提示消息
	tips: function(msg) {
		var tipStr = '<div class="tips animated"><span>' + msg + '</span></div>';
		$("body").append(tipStr);
		var w = $(".tips").width();
		var h = $(".tips").height();
		$(".tips").css({
			"margin-left": -w / 2 + "px",
			"margin-top": -h / 2 + "px"
		})
		$(".tips").show().addClass("bounceIn");
		tool.tipsDel();
	},
	tipsDel: function() {
		setTimeout(function() {
			$(".tips").remove()
		}, 1000)
	},
	// 设置内容高度
	setHight: function() {
		$(".Left").css("height", "inherit");
		var leftH = $(".Left").height(),
			RightH = $(".Right").height();
		if (leftH > RightH) {
			$(".Left").height(leftH)
		} else {
			$(".Left").height(RightH)
		}
	},
	// 节流方法
	throttle: function(handle, wait) {
		var lastTime = 0;
		return function() {
			//arguments[event]
			var nowTime = new Date().getTime();
			if (nowTime - lastTime > wait) {
				// handle.apply(this, arguments); //改变this指向
				handle();
				lastTime = nowTime;
			}
		}
	}
}

// 左侧导航
$(".columnBox h1 a").click(function() {
	var number = '';
	var _this = $(this);
	if (_this.hasClass("receive")) {
		number = 1;
	} else if (_this.hasClass("send")) {
		number = 2;
	} else if (_this.hasClass("draft")) {
		number = 3;
	} else if (_this.hasClass("delete")) {
		number = 4;
	}
	$(".operate li a.delete").attr("column-id", number);
	$(".columnBox h1 a.cur").removeClass("cur");
	$(".columnBox dl a").removeClass("curB");
	$(this).toggleClass("cur");
	$(this).parent().parent().siblings().children("dl").slideUp(100);
	$(this).parent().siblings("dl").slideToggle(200);
})
$(".columnBox dl a").click(function() {
	$(".columnBox h1 a.cur").removeClass("cur");
	$(".columnBox dl a").removeClass("curB");
	$(this).toggleClass("curB");
});
